package com.minshenglife.zanzan.pub.utils.spring;

import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import com.nationsky.pub.utils.DES;


public class EncryptablePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {  
  
    protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)  
        throws BeansException {  
            try {  
                String username = props.getProperty("jdbc.user");  
                if (username != null) {  
                    props.setProperty("jdbc.user", DES.decryptDES(username));  
                }  
                  
                String password = props.getProperty("jdbc.password");  
                if (password != null) {  
                    props.setProperty("jdbc.password", DES.decryptDES(password));  
                }  
                  
                String url = props.getProperty("jdbc.url");  
                if (url != null) {  
                    props.setProperty("jdbc.url", DES.decryptDES(url ));  
                }  
                  
                super.processProperties(beanFactory, props);  
            } catch (Exception e) {  
                e.printStackTrace();  
                throw new BeanInitializationException(e.getMessage());  
            }  
        }  
    
    public static void main(String[] asdf){
    	try {
			//String str=DES.encryptDES("jdbc:oracle:thin:@new6600.msidc.minshenglife.com:1521:intgtest11");
			String str=DES.encryptDES("jdbc:oracle:thin:@new6600.msidc.minshenglife.com:1521:intgtest11");
			
			String str1=DES.encryptDES("zzapp");
			System.out.print(str1);
			System.out.println(DES.decryptDES(str1));
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
	
}
